class SessionsController < ApplicationController
  def new
  end

  def create
    if user = User.admin_authenticate(params[:name], params[:password])
      session[:user_id] = user.id
      session[:user_type] = 'admin'
      redirect_to users_url
    elsif user = User.librarian_authenticate(params[:name], params[:password])
      session[:user_id] = user.id
      session[:user_type] = 'librarian'
      redirect_to librarian_url
    elsif user = User.student_authenticate(params[:name], params[:password])
      session[:user_id] = user.id
      session[:user_type] = 'student'
      redirect_to student_index_url
    else
      redirect_to login_url, :alert => "Invalid user/password combination"
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to home_url, :notice => "Logged out"
  end
end
